package org.pine.manager;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.pine.manager.bo.RoleBo;
import org.pine.manager.convertor.RoleConvertor;
import org.pine.manager.query.RoleQuery;
import org.pine.model.entity.Role;
import org.pine.model.mapper.RoleMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author pine
 * @version v1.0
 * @since 2025-04-19 15:24
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class RoleManager extends BaseManager<RoleMapper, Role, RoleBo, RoleQuery, RoleConvertor> {


    @Override
    public LambdaQueryWrapper<Role> encapsulateQueryWrapper(RoleQuery query) {
        LambdaQueryWrapper<Role> queryWrapper = super.encapsulateQueryWrapper(query);

        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getCode()), Role::getCode, query.getCode());
        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getName()), Role::getName, query.getName());
        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getRoleType()), Role::getRoleType, query.getRoleType());
        queryWrapper.in(ObjectUtil.isNotEmpty(query.getRoleTypeList()), Role::getRoleType, query.getRoleTypeList());
        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getStatus()), Role::getStatus, query.getStatus());
        queryWrapper.in(ObjectUtil.isNotEmpty(query.getStatusList()), Role::getStatus, query.getStatusList());

        return queryWrapper;
    }
}
